/*
 * ConstraintValidator.java
 * 
 * Created on 21-Aug-2007, 08:32:58
 * 
 * Copyright (C)
 *
 * This program is free software; you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation; either version 2 of the License, or (at your option) any later
 * version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
 * details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
 * Place, Suite 330, Boston, MA 02111-1307 USA
 */

package com.grubby.databean.constraints.validation;

import java.lang.annotation.Annotation;
import java.util.Set;

/**
 * A validator for Annotation based Constraints. Validators may validate
 * one or more constraint types.
 * @see ValidatorFactory
 * <p>
 * Note this has been adapted from an Annotation processing example created by 
 * Anders Holmgren of Sun Microsystems
 * </p>
 * 
 * @author Anders Holmgren, with alterations by A. HARMEL-LAW. 
 * E: andrew.harmel.law@gmail.com
 * @version 0.1
 */
public interface ConstraintValidator {
    
    /**
     * Validates the given value against the supplied constraint.
     * @param value the value that will be checked
     * @param constraint the constraint that the value will be checked against
     * @return a ConstraintViolation object if there was a violation of the
     * constraint, or null otherwise.
     * @throws IllegalArgumentException if constraint is either null or not one
     * of the constraint types supported by this validator
     */
    ConstraintViolation validate(Object value, Annotation constraint);

    /**
     * Returns the set of constraint types that this validator is capable
     * of validating. Note that the validator may not be registered for all the
     * constraint types that it supports.
     * @return the set of supported constraint types
     */
    Set<Class<? extends Annotation>> getSupportedConstraintTypes();
    
}
